
var static_data={
	provinces: 
		[
			['010','北京','BEIJING'],
			['020','上海','SHANGHAI'],
			['030','天津','TIANJIN'],
			['040','重庆','CHONGQING'],
			['050','广东省','GUANGDONG'],
			['060','江苏省','JIANGSU'],
			['070','浙江省','ZHEJIANG'],
			['080','安徽省','ANHUI'],
			['090','福建省','FUJIAN']
	    ],
	city:
		[
		 	[1, ['010','北京','BEIJING'],[['010','北京','BEIJING']]],
  			[1, ['020','上海','SHANGHAI'],[['020','上海','SHANGHAI']]],
  			[1, ['030','天津','TIANJIN'],[['030','天津','TIANJIN']]],
  			[1, ['040','重庆','CHONGQING'],[['040','重庆','CHONGQING']]],
  			[2, ['050','广东省','GUANGDONG'],[['050','广东省','GUANGDONG'],['050020','广州','GUANGZHOU'],
				['050030','潮州','CHAOZHOU'],['050040','东莞','DONGGUAN'],['050050','佛山','FOSHAN'],['050060','惠州','HUIZHOU'],
				['050070','清远','QINGYUAN'],['050080','汕头','SHANTOU'],['050090','深圳','SHENZHEN'],['050100','顺德','SHUNDE'],
				['050110','湛江','ZHANJIANG'],['050120','肇庆','ZHAOQING'],['050130','中山','ZHONGSHAN'],['050140','珠海','ZHUHAI']]],
  			[2, ['060','江苏省','JIANGSU'],[['060','江苏省','JIANGSU'],['060020','南京','NANJING'],['060030','常熟','CHANGSHU'],
				['060040','常州','CHANGZHOU'],['060050','昆山','KUNSHAN'],['060060','连云港','LIANYUNGANG'],['060070','南通','NANTONG'],
				['060080','苏州','SUZHOU'],['060090','太仓','TAICANG'],['060100','无锡','WUXI'],['060110','徐州','XUZHOU'],
				['060120','扬州','YANGZHOU'],['060130','镇江','ZHENJIANG']]],
  			[2, ['070','浙江省','ZHEJIANG'],[['070','浙江省','ZHEJIANG'],['070020','杭州','HANGZHOU'],['070030','宁波','NINGBO'],
				['070040','温州','WENZHOU'],['070050','绍兴','SHAOXING'],['070060','金华','JINHUA'],['070070','台州','TAIZHOU'],
				['070080','湖州','HUZHOU'],['070090','嘉兴','JIAXING'],['070100','衢州','QUZHOU'],['070110','丽水','LISHUI'],['070120','舟山','ZHOUSHAN']]],
  			[2, ['080','安徽省','ANHUI'],[['080','安徽省','ANHUI'],['080020','合肥','HEFEI'],['080030','安庆','ANQING'],['080040','蚌埠','BENGBU'],['080050','芜湖','WUHU']]],
  			[2, ['090','福建省','FUJIAN'],[['090','福建省','FUJIAN'],['090020','福州','FUZHOU'],['090030','泉州','QUANZHOU'],['090040','厦门','XIAMEN'],['090050','漳州','ZHANGZHOU']]]
		  
		],
	tradecategory:
		[
			['010','IT|互联网|通信|电子'],
			['020','金融|银行|保险']

		],
	trade:
		[
		 
		 	['010',['010010','计算机软件'],['010020','IT服务(系统/数据/维护)/多领域经营'],
				   ['010030','计算机硬件及网络设备'],
				   ['010040','互联网/电子商务'],['010050','网络游戏'],['010060','通信/电信/网络设备'],
				   ['010070','电子技术/半导体/集成电路务']],
			['020',['020010','金融/投资/基金/证券/期货'],['020030','银行'],['020040','保险'],
				   ['010040','房地产|建筑建设|物业']]
		]
};
(function($){
	var common={
		tempselect:'<div class="pop_cols_selector job-cols-list">'
+	      '<div class="selector_title">'
+	           '<strong></strong>'
+	           '<ul></ul>'
+	      '</div>'
+	      '<div class="col-list clearfix">'
+	          '<div class="cols"><h2>一级分类</h2><ul></ul></div>'
+	          '<div class="cols"><h2>二级分类</h2><ul></ul></div>'
+	     '</div>',
		temp_trade:[],
		current_category:0,
		pop_top:null,
		//根据大类找到小类的数据
		getChildarr:function(cur_array,code,target){
			for(var i in cur_array){
				if(cur_array[i][0]==code){
					var arr_category_trade=[],temp_category_trade="";
					for(var k=1;k<cur_array[i].length;k++){
						temp_category_trade='<li><label><input type="radio" name="scjobs" value="#id#" class="inall">#name#</label></li>';
						arr_category_trade.push(temp_category_trade.replace(/#id#/,cur_array[i][k][0]).replace(/#name#/,cur_array[i][k][1]));
					}
					target.children().remove();
					target.append($(arr_category_trade.join("")));
					break;
				}
			}
		},
		getcategory_name:function(cur_array,code){
			for(var i in cur_array){
				if(cur_array[i][0]==code){
					return cur_array[i][1];
				}
			}
		},
		trade_name:function(cur_array,code){
			var _temp=[];
			for(var i in cur_array){
				if(cur_array[i][0]==code.substring(0,3)){
					_temp=cur_array[i];
					break;
				}
			}
			for(var k=1;k<_temp.length;k++){
				if(_temp[k][0]==code){
					return _temp[k][1];
					break;
				}
			}
		},
		initstyle:function(obj){
			if(obj.val()==""){
				return;
			}
			var list=obj.val().split(","),
				li='<li name="#result#">#name#<em></em></li>',
				result = obj.parent().find(".pop_selection_result").empty().addClass("pop_selection_hide"),
				modify = obj.parent().find(".pop_selection_modify").addClass("pop_selection_hide");
				selection = obj.parent().find(".pop_selection").addClass("pop_selection_hide");
			switch(list[0].length){
				case 3:
					for(var i in list){
						var _li=li.replace(/#result#/,list[i]).replace(/#name#/,this.getcategory_name(static_data.tradecategory,list[i]));
						$(_li).appendTo(result);
					}
				break;
				case 6:
					for(var k in list){
						var _li=li.replace(/#result#/,list[k]).replace(/#name#/,this.trade_name(static_data.trade,list[k]));
						$(_li).appendTo(result);
					}
				break;
			}
			modify.removeClass("pop_selection_hide");
    		result.removeClass("pop_selection_hide");
			result.find("em").bind("click",function(){
				var index=result.find("em").index(this);
				list.splice(index,1);
				obj.val(list.join(","));
				$(this).parents("li").remove();
				if(obj.val()==""){
					modify.addClass("pop_selection_hide");
					result.addClass("pop_selection_hide");
					obj.parent().find(".pop_selection").removeClass("pop_selection_hide");
				}
				
			})
			
		},
		init_data:function(){
			common.pop_top=$(common.tempselect);
			var box = common.pop_top,
				result = box.find(".selector_title"),
				parentList = box.find(".col-list .cols:first").find("ul").empty(),
				childList = box.find(".col-list .cols:eq(1)").find("ul").empty(),
				resultList = result.find("ul"),arr_data=static_data.tradecategory,
				arr_category=[],temp_category="";
			for(var i in arr_data){
				temp_category='<li code="#id#"><a href="javascript:;">#name#</a></li>';
				arr_category.push(temp_category.replace(/#id#/,arr_data[i][0]).replace(/#name#/,arr_data[i][1]));
			}
			var temp_category=$(arr_category.join(""));
			parentList.append(temp_category);
			temp_category.first().addClass("current");
			temp_category.bind("click",function(){
				temp_category.get(common.current_category).className="";					
				$(this).addClass("current");
				common.getChildarr(static_data.trade,$(this).attr("code"),childList);
				common.current_category=temp_category.index($(this));
			});//绑定事件
			common.getChildarr(static_data.trade,static_data.tradecategory[0][0],childList);//绑定数据
		},
		select:function(){
			 var _input= common.pop_top.find(".col-list .cols:eq(1)").find("ul li input"),
			 	 i=0,
			 	 result=[];
			 _input.each(function(){
					if($(this).is(":checked")){
						//var _temp=[$(this).val(),$(this).get(0).nextSibling.nodeValue];
						var _temp=$(this).val();
						result.push(_temp);
						result.push(_temp);
						result.push(_temp);
					}
				}
			 )
			return result;
		},
		showDlg:function(obj){
			var _input=obj;
			$.dialog({
				title:"请选择",
				lock:true,
				padding:15,
				content:common.pop_top.get(0),
				okValue:"确定",
				cancelValue:"取消",
				cancel:function(){
				},
				ok:function(){
					var sel_data=common.select();
					_input.val(sel_data.join(","));
					common.initstyle(_input);
					
				}
			})
		}
	};
	$.fn.bind_dq=function(){
		common.init_data();	
		var selection="<span class=\"pop_selection input-text\"><em class=\"icon_selection\"><a href=\"javascript:;\"></a></em></span>",
		  	modify="<a class=\"pop_selection_modify\" href=\"javascript:;\">"+ "修改" +"</a>",
			result="<ul class=\"pop_selection_result "+ "input-text" + " pop_selection_inline_block\"></ul>";
			this.hide();
		this.each(function(){
			var _this=$(this);
				_selecction=$(selection).insertAfter(_this).width(_this.width()).bind("click",function(){common.showDlg(_this)});
				_result=$(result).addClass("pop_selection_hide").insertAfter(_selecction);
			$(modify).addClass("pop_selection_hide").insertAfter(_result).bind("click",function(){common.showDlg(_this)});
			common.initstyle(_this)////初始化样式
		})
	};
	
})(jQuery)